
<!--互联网售票机数据录入-->
<template>
  <div class="huLianWangShouPiaojiDataInput">
    <basic-container>
      <avue-crud
        ref="huLianWangShouPiaojiXianWang"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="getList">
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" v-if="false" @click="addData()">添加</el-button>
          <el-button type="primary"  size="mini" v-if="false" @click="deleteData">删除</el-button>
          <!--          <el-button type="primary"  size="mini">导入</el-button>-->
          <Export style="display: inline-flex;padding: 0px;width: auto" @importSuccess="getList"></Export>
          <el-button type="primary"  size="mini" @click="downTemplete()">模板下载</el-button>
          <el-button type="primary"  size="mini" v-if="false" @click="submitData">提交</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" @change="changeStation" clearable filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <!-- slot卡槽的名字为prop+Search，对应下面option的column里面的prop -->
        <template slot-scope="scope" slot="equipmentCodeSearch">
          <el-select v-model="searchForm.equipmentCode" placeholder="请选择" style="width: 150px" @change="getSheBei"  :disabled="showType==3" filterable>
            <el-option
              v-for="(item,index) in equipmentNumbers"
              :key="index"
              :label="item.equipmentCode"
              :value="item.equipmentCode">
            </el-option>
          </el-select>
        </template>
        <!-- <template slot="search" slot-scope="{row,size}">
          <el-form-item label="开始日期" style="margin-left: 20px">
            <el-date-picker clearable
                            v-model="searchForm.startTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="开始日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束日期" style="margin-left: 20px">
            <el-date-picker clearable
                            v-model="searchForm.endTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </template> -->
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <!-- <el-button type="text" size="small" v-if="scope.row.approvalStatus!=1" plain hidden="true" @click.stop="editor(scope.row)">编辑</el-button> -->
          <el-button type="text" size="small" plain @click.stop="preview(scope.row)">预览</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <Editor ref="Editor" v-if="isShowDiaEditor"></Editor>
    <Add ref="Add" v-if="isShowDiaAdd"></Add>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import Editor from './Editor';
  import Add from './Add.vue';
  import Export from './Export';
  import {
    clearSelect,
    getgetStationCodes,
    getLineCodes, setSearchFiledsEmpty,getSwPmDeviceOperationCodeList,getSwPmInternetTicketEquipmentCodeList,
  } from "../../../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../../../api/subwayRat/exportSelf";
  import {
    down_hlw_upload_Templete,
    getSwAuInputInternetTicketEquipmentDetails, submitSwAuInputInternetTicketEquipmentDetails,
    tableOption,
    updateSwAuInputInternetTicketEquipmentDetails
  } from "../../../../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/huLianWangShoupiaoji/huLianWangShouPiaojiXianWang";
  import {handleExcelResponse} from "../../../../../../util/util";
  export default {
    name: 'huLianWangShouPiaojiDataInput',
    components:{
      Editor,
      Add,
      Export
    },
    data() {
      return {
        isShowDiaEditor:false,
        isShowDiaAdd:false,
        option: {},
        listLoading: true,
        lineCodes:[],
        stationCodes:[],
        selectKeys:[],
        selectKeyVals:[],
        searchForm:{
          lineCode:'',
          stationCode:''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : [],
        equipmentNumbers: []
      }
    },
    computed: {
      ...mapGetters(['permissions']),
    },
    watch: {
    },
    created() {
      this.option=tableOption;
    },
    methods: {
      setSearchFiledsEmpty,
      refreshChange() {
        this.getList()
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        getSwAuInputInternetTicketEquipmentDetails(this.searchForm).then((response)=>{
          this.list = response.data.data;
          this.listLoading = false;
          this.page.total=response.data.total;
        });
      },
      async submitData(){
        if(this.selectKeyVals.length<=0){
          this.$message.warning("请选择提交数据");
          return ;
        }
        let res=await this.$confirm('是否确定要提交？', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        });
        if(!res){
          return;
        }
        submitSwAuInputInternetTicketEquipmentDetails({ids:this.selectKeyVals.join(",")}).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
          }else{
            this.$message.error("操作失败！");
          }
          clearSelect(this.$refs.huLianWangShouPiaojiXianWang);
        }).catch(e=>{
          this.$message.error("操作失败！");
        });

      },
      downTemplete(){
        down_hlw_upload_Templete().then(res=>{
          handleExcelResponse(res,"模板下载.xls");
        });

      },
      deleteData(){
        if(this.selectKeys.length<=0){
          this.$message.warning("未选择数据");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(Number(this.selectKeys[i].compareSubtotalTotal) && Number(this.selectKeys[i].compareTotalNumberSales)){
            this.$message.warning("请选择未对比的金额！");
            return;
          }
        }
        this.$confirm('确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          updateSwAuInputInternetTicketEquipmentDetails({ids:(this.selectKeyVals.join(",")),del_flag:1}).then(res=>{
            if(res.data.code==0){
              this.$message.success("操作成功！");
              this.getList();
            }else{
              this.$message.error("操作失败！");
            }
            clearSelect(this.$refs.huLianWangShouPiaojiXianWang);
          }).catch(e=>{
            this.$message.error("操作失败！");
          });
        }).catch(() => {

        });
      },
      addData(){
        this.isShowDiaAdd=true;
        this.$nextTick(()=>{
          this.$refs.Add.dialogVisible=true;
          this.$refs.Add.recallShow(null,null,2);
        })
      },
      editor(row){
        this.isShowDiaEditor=true;
        this.$nextTick(()=>{
          this.$refs.Editor.dialogVisible=true;
          this.$refs.Editor.recallShow(null,row,2);
        })
      },
      preview(row){
        this.isShowDiaEditor=true;
        this.$nextTick(()=>{
          this.$refs.Editor.dialogVisible=true;
          this.$refs.Editor.recallShow(null,row,3);
        })
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      async exportData(){ // 导出
        let p={};
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        if(this.selectKeys.length>0){
          exportDataToExcel(this.selectKeys,this.option.column,'互联网售票机数据录入');
        }else {
          let res=await getSwAuInputInternetTicketEquipmentDetails(p);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'互联网售票机数据录入');
        }
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
          this.searchForm.stationCode='';
          this.searchForm.equipmentCode = '';
        })
      },
      changeStation(v){
        this.searchForm.equipmentCode = '';
        this.getSheBei();
      },
      getSheBei(){
          getSwPmInternetTicketEquipmentCodeList({lineCode:this.searchForm.lineCode,stationCode:this.searchForm.stationCode}).then(r=>{
            this.equipmentNumbers=r.data.data;
        });
      },
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
    }
  }
</script>
<style lang="scss">
  .huLianWangShouPiaojiDataInput {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
    .avue-form__group{

    }
  }
</style>
